package com.googlecode.dgwt.client.dijit.base;

import com.google.gwt.event.dom.client.HasScrollHandlers;
import com.google.gwt.user.client.ui.UIObject;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public interface HasScrollBars extends HasScrollHandlers {

    /**
     * Ensures that the specified item is visible, by adjusting the widget's
     * scroll position.
     * 
     * @param item
     *            the item whose visibility is to be ensured
     */
    public void ensureVisibility(UIObject child);

    /**
     * Sets the horizontal scroll position.
     * 
     * @param position
     *            the new horizontal scroll position, in pixels
     */
    public void setHorizontalScrollPosition(int position);

    /**
     * Gets the horizontal scroll position.
     * 
     * @return the horizontal scroll position, in pixels
     */
    public int getHorizontalScrollPosition();

    /**
     * Sets the vertical scroll position.
     * 
     * @param position
     *            the new vertical scroll position, in pixels
     */
    public void setVerticalScrollPosition(int position);

    /**
     * Gets the vertical scroll position.
     * 
     * @return the vertical scroll position, in pixels
     */
    public int getVerticalScrollPosition();

    /**
     * Scroll to the bottom of this widget.
     */
    public void scrollToBottom();

    /**
     * Scroll to the far left of this widget.
     */
    public void scrollToLeft();

    /**
     * Scroll to the far right of this widget.
     */
    public void scrollToRight();

    /**
     * Scroll to the top of this widget.
     */
    public void scrollToTop();

    /**
     * Sets the visibility of the horizontal scroll bar for this widget.
     * 
     * @param visibility
     *            the scroll bar visibility
     */
    public void setHorizontalScrollBar(ScrollBarVisibility visibility);

    /**
     * Gets the visibility of the horizontal scroll bar for this widget.
     * 
     * @return the scroll bar visibility
     */
    public ScrollBarVisibility getHorizontalScrollBar();

    /**
     * Sets the visibility of the vertical scroll bar for this widget.
     * 
     * @param visibility
     *            the scroll bar visibility
     */
    public void setVerticalScrollBar(ScrollBarVisibility visibility);

    /**
     * Gets the visibility of the vertical scroll bar for this widget.
     * 
     * @return the scroll bar visibility
     */
    public ScrollBarVisibility getVerticalScrollBar();

    /**
     * Sets the visibility of the scroll bars for this widget.
     * 
     * @param vertical
     *            the vertical scroll bar visibility
     * @param horizontal
     *            the horizontal scroll bar visibility
     */
    public void setScrollBars(ScrollBarVisibility vertical, ScrollBarVisibility horizontal);

    
    public enum ScrollBarVisibility {
        HIDDEN("hidden"), 
        FIXED("scroll"), 
        AUTO("auto");
        
        private String overflowValue;
        
        ScrollBarVisibility(String overflowValue){
            this.overflowValue = overflowValue;
        }
        
        public String getOverflowValue(){
            return overflowValue;
        }
        
        public static ScrollBarVisibility parse(String overflowValue){
            if (AUTO.overflowValue.equalsIgnoreCase(overflowValue)){
                return AUTO;
            }
            if (FIXED.overflowValue.equalsIgnoreCase(overflowValue)){
                return FIXED;
            }
            if (HIDDEN.overflowValue.equalsIgnoreCase(overflowValue)){
                return HIDDEN;
            }            
            return null;
        }
    }

}
